<?php

define("APP_ROOT", dirname(__DIR__));
include 'common.php';

class controller extends common {

    public $db;
    public $redis;

    function __construct($dbclass, $redis) {
        parent::__construct();
        //数据库操作句柄
        $this->db = $dbclass;
        $this->redis = $redis;
    }

    /**
     * 监测账号密码
     * @param string $name
     * @param string $pwd
     * @return boolean
     */
    function check_login($name = '', $pwd = '') {
        $use_pwd = '';
        $use_pwd = trim($name) . '_' . trim($pwd);
        $user['id_1'] = 'yanlei_123456';
        $user['id_2'] = 'heyiwei_123456';
        $user['id_3'] = 'zgc_123456';
        $user_od = '';
        foreach ($user as $key => $value) {
            if ($value == $use_pwd) {
                $user_od = $key;
            }
        }
        if ($user_od) {
            return $user_od;
        } else {
            return false;
        }
    }

    //检测token是否合法
    function check_token($uid, $token) {
        //不存在redis的key 假key
        $encode_token = $this->redis->get($uid);
        if ($token != $encode_token) {
            return false;
        }
        $user_info = $this->public_decode($token);
        if (md5($user_info['uid']) != $uid) {
            return false;
        }
        return true;
    }

}
